package com.wxzz.elearing.course.api.app;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.course.dto.TrainSurveyByWxUserDto;
import com.wxzz.elearing.course.dto.TrainSurveyIsPassDto;
import com.wxzz.elearing.course.entity.CurriculumSectionTopic;
import com.wxzz.elearing.course.entity.StudyPlan;
import com.wxzz.elearing.course.entity.TrainSurvey;
import com.wxzz.elearing.course.service.ITrainSurveyService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wx-train-survey")
@Api(tags = "培训调查(小程序)")
public class WxTrainSurveyController {

    @Autowired
    private ITrainSurveyService trainSurveyService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "培训调查结算调用(小程序)", notes = "培训调查结算调用(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "isPassTrainSurvey", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<StudyPlan>>> isPassTrainSurvey(@RequestHeader String token, @RequestBody TrainSurveyIsPassDto trainSurveyIsPassDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        StudyPlan studyPlan = new StudyPlan();
        return trainSurveyService.isPassTrainSurvey(jsonObject.getLong("id"), trainSurveyIsPassDto);
    }


    @ApiOperation(value = "根据id查询培训调查详情(小程序)", notes = "根据id查询培训调查详情(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "wxSelectTrainSurveyDetail/{trainSurveyId}", method = RequestMethod.POST)
    public ReturnVO<TrainSurvey> wxSelectTrainSurveyDetail(@RequestHeader String token, @PathVariable Long trainSurveyId) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return trainSurveyService.wxSelectTrainSurveyDetail(jsonObject.getLong("id"), trainSurveyId);
    }

    @ApiOperation(value = "查询当前用户培训调查(小程序)", notes = "查询当前用户培训调查(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listTrainSurveyByWxUserId", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<TrainSurvey>>> listTrainSurveyByWxUserId(@RequestHeader String token, @RequestBody TrainSurveyByWxUserDto trainSurveyByWxUserDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return trainSurveyService.listTrainSurveyByWxUserId(jsonObject.getLong("id"), trainSurveyByWxUserDto);
    }

    @ApiOperation(value = "列出培训调查记录(小程序)", notes = "列出培训调查记录(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listTrainSurveyByTrainSurveyHistory/{trainSurveyId}", method = RequestMethod.POST)
    public ReturnVO<List<CurriculumSectionTopic>> listTrainSurveyByTrainSurveyHistory(@RequestHeader String token, @PathVariable Long trainSurveyId) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return trainSurveyService.listTrainSurveyByTrainSurveyHistory(jsonObject.getLong("id"), trainSurveyId);
    }
}
